#define _CRT_SECURE_NO_WARNINGS 1
#include "Queue.h"
void QueueInit(Queue* q)
{
	assert(q);
	q->phead = q->ptail = NULL;
	q->size = 0;
}
void QueuePush(Queue* q, QDateType index)
{
	assert(q);
	QueueNode* buynode = (QueueNode*)malloc(sizeof(QueueNode));
	if (buynode == NULL)
	{
		perror("malloc error!");
		exit(1);
	}
	buynode->value = index;
	buynode->next = NULL;
	if (q->size == 0)
	{
		q->phead = q->ptail = buynode;
	}
	else
	{
		q->ptail->next = buynode;
		q->ptail = buynode;
	}
	q->size++;
}
void QueuePop(Queue* q)
{
	assert(q && q->size);
	if (q->phead == q->ptail)
	{
		free(q->phead);
		q->phead = q->ptail = NULL;
	}
	else
	{
		Queue* Del = q->phead;
		q->phead = q->phead->next;
		free(Del);
		Del = NULL;
	}
	q->size--;
}
QDateType QueueFront(Queue* q)
{
	assert(q && q->size);
	return q->phead->value;
}
QDateType QueueBack(Queue* q)
{
	assert(q && q->size);
	return q->ptail->value;
}
int QueueSize(Queue* q)
{
	assert(q);
	return q->size;
}
bool QueueEmpty(Queue* q)
{
	assert(q);
	return !q->size;
}
void QueueDestroy(Queue* q)
{
	assert(q);
	QueueNode* pcur = q->phead;
	QueueNode* next = q->phead;
	while (pcur)
	{
		next = pcur->next;
		free(pcur);
		pcur = next;
	}
	q->phead = q->ptail = NULL;
	q->size = 0;
}